/**
 * 
 */
package com.business.commons.baseUtil;

import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * @author ddr
 *
 */
public class NumberFormatUtil {

	
	
	private NumberFormatUtil(){
	}
	
	
	private static NumberFormatUtil instance;
	
	public static NumberFormatUtil get() {
		if(instance == null ){
			instance = new NumberFormatUtil(); 
		}
		return instance;
	}
	
	public static final DecimalFormat NO_ZERO_FMT = new DecimalFormat("0.##########");
	
	/**
	 * 去除末尾的.00
	 * 如21.00 --> 21
	 * 21.010 -->21.01
	 * @param value
	 * @return 
	 */
	public  BigDecimal decimalFormatNoZero(String value){
		if(value==null){
			return null;
		}
		if(value.contains(".") && value.endsWith("0")){
			BigDecimal bd = new BigDecimal (NO_ZERO_FMT.format(new Double(value)));
			return bd;
		}
		
		return new BigDecimal(value);
	}
	
	public  BigDecimal decimalFormatNoZero(BigDecimal value){
		if(value!=null){
			return new BigDecimal (NO_ZERO_FMT.format(value));
		}
		return null;
	}
	
	
	
	
	
	
	
	public static void main(String[] args) {
		System.out.println(NumberFormatUtil.get().decimalFormatNoZero(new BigDecimal("0.0000")));
	}
	
}
